<template>
  <div class="content">
    <dt-search ref="search" :labelWidth="100" :xl="5" :xlBtn="4"></dt-search>
    <div class="tipBox">
      <div class="tips">
        <p>
          共有{{ topRocerdData.privacyNum }}个隐私号,案场承接业务使用中{{
            topRocerdData.tospurNum
          }}个,外呼号租用{{ topRocerdData.leaseNum }}个,闲置{{ topRocerdData.idleNum }}个，异常{{
            topRocerdData.errorNum
          }}个
        </p>
      </div>
      <div class="handles">
        <Button type="primary" @click="callRecord" v-if="unlocking('0213020500')">所有通话记录</Button>
        <Button type="primary" @click="exportData" style="margin-left: 10px" v-if="unlocking('0213020600')">
          导出Excel
        </Button>
      </div>
    </div>

    <dt-grid ref="table" :select="{ sort: sortCase }" :columns="columns" :page="page" :onFetch="onFetch" />

    <privacy-number-details ref="detail"></privacy-number-details>
  </div>
</template>

<script>
  import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
  import dt from '@dt/dt'
  import columnOpt from './opt/privacyNumberColumn'
  import privacyNumberSearch from './opt/privacyNumberSearch'
  import privacyNumberDetails from './components/privacyNumberDetails'
  import businessCommonMgr from '@/biz/businessReport/businessCommon'
  import receiverMgr from '@/biz/receiver/receiver'
  export default {
    components: {
      privacyNumberDetails
    },
    data() {
      return {
        continuousTimeOrderBy: '',
        topRocerdData: {
          privacyNum: '0',
          tospurNum: '0',
          leaseNum: '0',
          idleNum: '0',
          errorNum: '0'
        },

        leaveUserIds: [],
        paramsAll: {},
        tipFlag: true,
        sourcedata: [],
        targetdata: [],
        formValidate: {
          companyIds: [],
          buildingId: ''
        },
        columns: [],
        page: {
          total: 0,
          current: 1
        },
        totalLeaveNum: 0,
        noReceiverCase: {
          label: '',
          value: ''
        },
        leaveCaseFlag: false
      }
    },
    mounted() {
      // this.getColumns()

      this.$refs.table.init(this, new columnOpt(this))
      this.$refs.search.init(this.$refs.table, new privacyNumberSearch(this).options(), this.formValidate)
      this.$refs.table.fetch()

      this.usPrivacyNumberManageStatistics()
    },

    methods: {
      sortCase(sort) {
        console.log(sort, 'sort')
        if (sort.prop == '_txt_statusContinueTime' && sort.order == 'asc') {
          this.continuousTimeOrderBy = 1
        } else if (sort.prop == '_txt_statusContinueTime' && sort.order == 'desc') {
          this.continuousTimeOrderBy = 2
        } else {
          this.continuousTimeOrderBy = ''
        }
        this.$refs.table.fetch()
      },
      // 使用记录
      useRecord(info) {
        this.$refs.detail.show(info.privacyNumber)
      },

      // go通话记录
      callRecord(val) {
        console.log(val, 'vvv')
        if (val && val.privacyNumber) {
          this.$router.push({
            path: '/clueManage/privacyCallRecord',
            query: {
              type: 'privacy',
              privacyNumber: val.privacyNumber
            }
          })
        } else {
          this.$router.push({
            path: '/clueManage/privacyCallRecord',
            query: {
              type: 'privacy'
            }
          })
        }
      },

      exportData() {
        receiverMgr.usPrivacyNumberManageExport(this.paramsAll)
      },
      // 获取统计数据
      usPrivacyNumberManageStatistics() {
        let params = {}
        receiverMgr.usPrivacyNumberManageStatistics(params).then((res) => {
          this.topRocerdData = res
        })
      },

      // 列表数据
      onFetch(data, val) {
        console.log(data, 'data')
        this.paramsAll = data
        if (this.continuousTimeOrderBy) {
          this.paramsAll.continuousTimeOrderBy = this.continuousTimeOrderBy
        }

        return receiverMgr
          .usPrivacyNumberManage(this.paramsAll)
          .then((res) => {
            console.log(res, 'vvvvv')
            this.page.total = res.total

            return res.list
          })
          .catch((err) => {
            this.total = 0
          })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    padding: 20px;
  }

  .tipBox {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding-bottom: 10px;
  }

  // 承接人
  .tips {
    background: rgba(250, 205, 145, 1);
    display: inline-block;
    padding: 6px 30px;

    span {
      color: #2d8cf0;
      margin-right: 20px;
    }
  }
</style>
